/**
 * @Title: AnnounceListController.java
 * @Package com.zll.ccp.controller.announce
 * @author zhanglinlu
 * @date 2019年5月20日 下午2:52:55
 */
package com.zll.ccp.controller.announce;

import com.zll.ccp.annotation.RequireOwn;
import com.zll.ccp.constants.Constant;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zll.ccp.service.IAnnounceService;

/**
 * @ClassName: AnnounceListController
 * @Description: 列表
 * @author zhanglinlu
 * @date 2019年5月20日 下午2:52:55
 * 
 */
@Controller
public class AnnounceListController {
    @Autowired
    private IAnnounceService announceService;

    /**
     * @Title: announceList
     * @Description: 进入公告列表
     * @return
     */
    @RequestMapping("/announcelist")
    public String announceList() {
        return "announce/announceList";
    }

    /**
     * @Title: getTableData
     * @Description: 根据筛选条件获取列表数据
     * @param pTitle 标题
     * @param pCt 创建时间
     * @return
     */
    @GetMapping("/tabledata")
    @ResponseBody
    public Object getTableData(String pTitle, Long pCT) {
        if (StringUtils.isBlank(pTitle)) {
            pTitle = null;
        }
        String sPCT = null;
        if (0 != pCT) {
            sPCT = DateFormatUtils.format(pCT, "yyyy-MM-dd");
        }
        return announceService.getAnnouncesByFilter(pTitle, sPCT);
    }

    /**
     * @Title: deleteAnnounce
     * @Description: 删除公告
     * @param id 主键
     * @return
     */
    @RequiresRoles(Constant.ROLE_ADMIN)
    @RequestMapping("/deleteannounce")
    @ResponseBody
    public Object deleteAnnounce(String id) {
        announceService.deleteAnnounce(id);
        return null;
    }
}
